package cc.momas.momall.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cc.momas.common.utils.E3Result;
import cc.momas.common.vo.EasyUIDataGridResult;
import cc.momas.momall.po.TbContent;
import cc.momas.momall.service.IContentService;

@Controller
public class ContentController {

	@Autowired
	private IContentService conSvc;

	
	@RequestMapping(value="/content/save")
	@ResponseBody
	public E3Result saveContect(TbContent content) {
		int i = conSvc.save(content);
		return i > 0 ? E3Result.ok() : E3Result.build(501,"保存失败");
	}
	

	@RequestMapping(value = "/content/query/list")
	@ResponseBody
	public EasyUIDataGridResult getDataGrid(@RequestParam("categoryId") Long catId, Integer page, Integer rows) {
		EasyUIDataGridResult list =  conSvc.getContentList(catId,page,rows);
		return list;
	}

	@RequestMapping(value="/rest/content/edit")
	@ResponseBody
	public E3Result updateContent(TbContent content) {
		conSvc.updateContentByIdSelective(content);
		return E3Result.ok();
	}
	
	@RequestMapping(value="/content/delete")
	@ResponseBody
	public E3Result deleteById(String ids) {
		if(ids == null) {
			return E3Result.error("");
		}
		conSvc.deleteById(ids);
		return E3Result.ok();
	}

}
